/*
 * Copyright (C) 2014 Realtek Semiconductor Corp.
 * All Rights Reserved.
 *
 * This program is the proprietary software of Realtek Semiconductor
 * Corporation and/or its licensors, and only be used, duplicated,
 * modified or distributed under the authorized license from Realtek.
 *
 * ANY USE OF THE SOFTWARE OTHER THAN AS AUTHORIZED UNDER
 * THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
 *
 */


#include "app_basic.h"

MIB_TABLE_INFO_T gMibVoIPVoiceCTPTableInfo;
MIB_ATTR_INFO_T  gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_ATTR_NUM];
MIB_TABLE_VOIPVOICECTP_T gMibVoIPVoiceCTPDefRow;
MIB_TABLE_OPER_T gMibVoIPVoiceCTPOper;


GOS_ERROR_CODE VoIPVoiceCTPDrvCfg(void* pOldRow, void* pNewRow, MIB_OPERA_TYPE operationType, MIB_ATTRS_SET attrSet, UINT32 pri)
{
	MIB_TABLE_VOIPVOICECTP_T    *pMibVoIPVoiceCtp = (MIB_TABLE_VOIPVOICECTP_T*)pNewRow;
	omci_voice_vendor_t         voice_vendor;
	MIB_TABLE_VOIPCONFIGDATA_T   mibVcd;

	voice_vendor = (gInfo.voiceVendor ? VOICE_VENDOR_RTK : VOICE_VENDOR_NONE);

    switch (operationType)
    {
    case MIB_GET:
		break;
    case MIB_DEL:
		OMCI_PRINT("SIPUserData --> DEL");
		mibVcd.EntityId = 0;
		if (GOS_OK == MIB_Get(MIB_TABLE_VOIPCONFIGDATA_INDEX, &mibVcd, sizeof(MIB_TABLE_VOIPCONFIGDATA_T)) &&
		mibVcd.VOIPConfigurationMethodUsed == VCD_CFG_METHOD_USED_OMCI)
		{
		VOICE_WRAPPER(omci_voice_config_reset);
		}
		break;
    default:
		omci_voice_vendor_service_cb(voice_vendor, (void *)pMibVoIPVoiceCtp);
    		break;
    }
    return GOS_OK;
}
GOS_ERROR_CODE mibTable_init(MIB_TABLE_INDEX tableId)
{
    gMibVoIPVoiceCTPTableInfo.Name = "VoIPVoiceCTP";
    gMibVoIPVoiceCTPTableInfo.ShortName = "VOIPVCTP";
    gMibVoIPVoiceCTPTableInfo.Desc = "VoIP voice CTP";
    gMibVoIPVoiceCTPTableInfo.ClassId = (UINT32)(OMCI_ME_CLASS_VOIP_VOICE_CTP);
    gMibVoIPVoiceCTPTableInfo.InitType = (UINT32)(OMCI_ME_INIT_TYPE_OLT);
    gMibVoIPVoiceCTPTableInfo.StdType = (UINT32)(OMCI_ME_TYPE_STANDARD);
    gMibVoIPVoiceCTPTableInfo.ActionType = (UINT32)(OMCI_ME_ACTION_CREATE | OMCI_ME_ACTION_DELETE | OMCI_ME_ACTION_SET | OMCI_ME_ACTION_GET);
    gMibVoIPVoiceCTPTableInfo.pAttributes = &(gMibVoIPVoiceCTPAttrInfo[0]);

    gMibVoIPVoiceCTPTableInfo.attrNum = MIB_TABLE_VOIPVOICECTP_ATTR_NUM;
    gMibVoIPVoiceCTPTableInfo.entrySize = sizeof(MIB_TABLE_VOIPVOICECTP_T);
    gMibVoIPVoiceCTPTableInfo.pDefaultRow = &gMibVoIPVoiceCTPDefRow;

    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].Name = "EntityId";
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_USERPROTOCOLPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].Name = "UserProtocolPointer";
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_PPTPPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].Name = "PPTPPointer";
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_VOIPMEDIAPROFILEPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].Name = "VOIPMediaProfilePointer";
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_SIGNALLINGCODE_INDEX - MIB_TABLE_FIRST_INDEX].Name = "SignallingCode";

    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Entity ID";
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_USERPROTOCOLPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "User protocol pointer";
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_PPTPPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "PPTP pointer";
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_VOIPMEDIAPROFILEPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "VOIP media profile pointer";
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_SIGNALLINGCODE_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Signalling code";

    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT16;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_USERPROTOCOLPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT16;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_PPTPPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT16;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_VOIPMEDIAPROFILEPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT16;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_SIGNALLINGCODE_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT8;

    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].Len = 2;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_USERPROTOCOLPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].Len = 2;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_PPTPPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].Len = 2;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_VOIPMEDIAPROFILEPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].Len = 2;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_SIGNALLINGCODE_INDEX - MIB_TABLE_FIRST_INDEX].Len = 1;

    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = TRUE;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_USERPROTOCOLPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_PPTPPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_VOIPMEDIAPROFILEPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_SIGNALLINGCODE_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;

    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_USERPROTOCOLPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_PPTPPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_VOIPMEDIAPROFILEPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_SIGNALLINGCODE_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;

    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_USERPROTOCOLPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_PPTPPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_VOIPMEDIAPROFILEPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_SIGNALLINGCODE_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_DEC;

    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_SBC;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_USERPROTOCOLPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE | OMCI_ME_ATTR_ACCESS_SBC;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_PPTPPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE | OMCI_ME_ATTR_ACCESS_SBC;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_VOIPMEDIAPROFILEPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE | OMCI_ME_ATTR_ACCESS_SBC;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_SIGNALLINGCODE_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE | OMCI_ME_ATTR_ACCESS_SBC;

    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_USERPROTOCOLPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_PPTPPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_VOIPMEDIAPROFILEPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_SIGNALLINGCODE_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;

    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_USERPROTOCOLPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_PPTPPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_VOIPMEDIAPROFILEPOINTER_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibVoIPVoiceCTPAttrInfo[MIB_TABLE_VOIPVOICECTP_SIGNALLINGCODE_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;

    gMibVoIPVoiceCTPDefRow.EntityId = 0;
    gMibVoIPVoiceCTPDefRow.UserProtocolPointer = 0;
    gMibVoIPVoiceCTPDefRow.PPTPPointer = 0xffff;
    gMibVoIPVoiceCTPDefRow.VOIPMediaProfilePointer = 0;
    gMibVoIPVoiceCTPDefRow.SignallingCode = 0;

    memset(&gMibVoIPVoiceCTPOper, 0x0, sizeof(MIB_TABLE_OPER_T));
    gMibVoIPVoiceCTPOper.meOperDrvCfg = VoIPVoiceCTPDrvCfg;
    gMibVoIPVoiceCTPOper.meOperConnCheck = NULL;
    gMibVoIPVoiceCTPOper.meOperDump = omci_mib_oper_dump_default_handler;
    gMibVoIPVoiceCTPOper.meOperConnCfg = NULL;
    gMibVoIPVoiceCTPOper.meOperAvlTreeAdd = NULL;
    gMibVoIPVoiceCTPOper.meOperAlarmHandler = NULL;
    gMibVoIPVoiceCTPOper.meOperTestHandler = NULL;

    MIB_TABLE_VOIPVOICECTP_INDEX = tableId;
    MIB_InfoRegister(tableId, &gMibVoIPVoiceCTPTableInfo, &gMibVoIPVoiceCTPOper);
    MIB_RegisterCallback(tableId, NULL, NULL);

    return GOS_OK;
}

